package com.atguigu.spzx.model.vo.common;

import lombok.Data;

@Data
public class Result<T> {
    //状态码 200代表成功
    private Integer code;
    //状态码的描述
    private String message;
    //成功的响应数据
    private T data;
    //私有化构造器
    private Result(){}
    //手动指定状态码信息构建 result对象
    public static <T> Result<T> setResult(Integer code , String message , T data){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setData(data);
        result.setMessage(message);
        return result;
    }
    //通过枚举对象构建 result对象
    public static <T> Result<T> setResult(ResultCodeEnum codeEnum , T data){
        return setResult(codeEnum.getCode() , codeEnum.getMesssage() , data);
    }
    //默认成功
    public static<T> Result<T> ok(){
        return setResult(ResultCodeEnum.SUCCESS , null);
    }
    //默认失败
    public static<T> Result<T> error(){
        return setResult(ResultCodeEnum.ERROR , null);
    }
    //链式调用设置属性值
    public Result<T> code(Integer code){
        this.setCode(code);
        return this;
    }
    public Result<T> message(String message){
        this.setMessage(message);
        return this;
    }
    public Result<T> data(T data){
        this.setData(data);
        return this;
    }
}